﻿using ICAM.DataLayer;
using ICAM.Model;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ICAM.View
{
    /// <summary>
    /// StackedView.xaml 的交互逻辑
    /// </summary>
    public partial class StackedView : UserControl
    {
        public SeriesCollection SeriesCollection { get; set; }
        public string[] Labels { get; set; }
        public StackedView()
        {
            InitializeComponent();
            Brush brush = (Brush)new BrushConverter().ConvertFromString("#1D77F2");

            this.Loaded += StackedView_Loaded;
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            this.CusToolTip.Update();
        }

        private void StackedView_Loaded(object sender, RoutedEventArgs e)
        {
            var mainViewModule = this.DataContext as MainViewModule;
            if (mainViewModule == null)
                return;
            var list = mainViewModule.AlaramStatic;
            if (list == null || list.Count == 0)
                return;
            SeriesCollection = new SeriesCollection
            {
                new StackedColumnSeries
                {
                    Title = "未处理",
                    StackMode= StackMode.Values,
                    Values = new ChartValues<ObservableValue>
                    {
                        new ObservableValue(list.FirstOrDefault(t=>t.AlarmLever=="1").UnDealNum),
                        new ObservableValue(list.FirstOrDefault(t=>t.AlarmLever=="2").UnDealNum),
                        new ObservableValue(list.FirstOrDefault(t=>t.AlarmLever=="3").UnDealNum),
                    },

                    DataLabels = false,
                },
                new StackedColumnSeries
                {
                    Title = "已忽略",
                    StackMode= StackMode.Values,
                    Values = new ChartValues<ObservableValue>
                    {
                        new ObservableValue(list.FirstOrDefault(t=>t.AlarmLever=="1").IgnoreNum),
                        new ObservableValue(list.FirstOrDefault(t=>t.AlarmLever=="2").IgnoreNum),
                        new ObservableValue(list.FirstOrDefault(t=>t.AlarmLever=="3").IgnoreNum),
                    },
                    DataLabels = false,
                },
                new StackedColumnSeries
                {
                    Title = "已处理",
                    StackMode= StackMode.Values,
                    Values = new ChartValues<ObservableValue>
                    {
                        new ObservableValue(list.FirstOrDefault(t=>t.AlarmLever=="1").DealNum),
                        new ObservableValue(list.FirstOrDefault(t=>t.AlarmLever=="2").DealNum),
                        new ObservableValue(list.FirstOrDefault(t=>t.AlarmLever=="3").DealNum),
                    },
                    DataLabels = false
                }
            };

            Labels = new[]
            {
                "一级", "二级","三级"
            };

            DataContext = this;
        }
    }
}
